package com.sdy;

import com.sdy.interceptor.ManagerInterceptor;
import com.sdy.interceptor.LoginInterceptor;
import com.sdy.interceptor.ChooseCompanyInterceptor;
import com.sdy.interceptor.ToPageInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class ResourceConfigAdapter implements WebMvcConfigurer {

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("添加Login拦截器");
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/management",
                        "/management/doLogin",
                        "/login/doRegist",
                        "/css/**",
                        "/vendors/**",
                        "/images/**",
                        "/js/**",
                        "/docs/**",
                        "/fonts.Roboto/**",
                        "/scss/**");

        System.out.println("添加ChooseCompany拦截器");
        registry.addInterceptor(new ChooseCompanyInterceptor())
                .addPathPatterns("/company/realStatement","/order","/serial","/notic");

        System.out.println("添加Manager拦截器");
        registry.addInterceptor(new ManagerInterceptor())
                .addPathPatterns("/company/choose","/management/toPage");

//        System.out.println("添加ToPage拦截器");
//        registry.addInterceptor(new ToPageInterceptor())
//                .addPathPatterns("/management/toPage");
    }

    /**
     * 解锁静态路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**","/static/**")
                .addResourceLocations("D:/IntelliJ IDEA 2018.2.4/IDEA Workspace/ShanDongJiaoYangManage/management_system/target/upload/","classpath:/static/");
    }
}
